package prickworlds.graphics;

import org.lwjgl.util.Color;

public class Explosion extends ParticleEffect {
	float x;
	float y;

	private static ParticleType type;

	static {
		Color[] colors = new Color[] { new Color(255, 180, 0),
				new Color(200, 100, 20), new Color(150, 110, 50, 100),
				new Color(50, 50, 50, 70), new Color(50, 50, 50, 30),
				new Color(50, 50, 50, 0) };
		// colors = new Color[] { new Color(255, 0, 0),
		// new Color(0, 0, 255) };
		Texture particleTexture = ParticleType.createStandardParticleTexture(32);
		type = new ParticleType(particleTexture);
		type.setFullLife(100);
		type.setColorGradient(new ColorGradient(colors));
	}

	public Explosion(float x, float y, float size) {
		super();
		this.x = x;
		this.y = y;

		final int nParticles = 10;

		for (int i = 0; i < nParticles; i++) {
			Particle p = new Particle(type);
			p.x = x;
			p.y = y;
			p.width = 1.2f * size;
			p.height = 1.2f * size;
			double angle = i * 2 * Math.PI / nParticles;
			float speed = (float) (Math.random() * 0.05f * size);
			p.velX = (float) Math.cos(angle) * speed;
			p.velY = (float) Math.sin(angle) * speed;
			super.addParticle(p);
		}
	}
}
